<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li {
            /* width: 30px;
            height: 30px; */
            width: 24px;
            height: 24px;
            background-image: url('./qq_face.png');
            background-repeat: no-repeat;
            list-style-type: none;
            float: left;
        }
        .qq-container li:first-child {
            background-position: 0 0;
        }
        .qq-container li:nth-child(2) {
            background-position: -30px 0;
        }
        .qq-container li:nth-child(3) {
            background-position: -60px 0;
        }
        .qq-container li:nth-child(4) {
            background-position: -90px 0;
        }
        .qq-container li:nth-child(5) {
            background-position: 0px -30px;
        }
    </style>
</head>
<body>
    <script src="./test.js"></script>
    <script>
        let str = '我是文本12022-08-22钱亮就哩[微笑][撇嘴][色]'
        let reg = /\[.*?\]/g
        let list = str.match(reg)

        let msgDiv = document.createElement('div');
        // let tempSpan= document.createElement('span');
        list.forEach(item => {
            let index = qq_faceMap.get(item)
            if (index >= 0) {
                let startIndex = str.indexOf(item)
                
                msgDiv.innerHTML = `<div 
                class='qqFaceInText' 
                ​title=${item}
                style='background-position: ${-(index%15)*29}px ${-(Math.floor(index/15))*29}px'
                \></div>`;
                str = str.replace(item,msgDiv)
            }
        })
        console.log(str)
    </script>
</body>
</html>